package com.fantasy.easy.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fantasy.easy.biz.domain.BizBase;
import com.fantasy.easy.biz.domain.BizCredit;
import com.fantasy.easy.biz.domain.BizData;
import com.fantasy.easy.biz.service.BizBaseService;
import com.fantasy.easy.biz.service.BizDataService;
import com.fantasy.easy.core.SessionSubjectUtils;
import com.fantasy.easy.core.entity.SysUserEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @Author sdehua-帅德华
 * @Email sdhstart@qq.com
 * @Date 2022/6/24 14:47
 * @Version 1.0
 **/
@RestController
@RequestMapping("data")
public class BizDataController {

    @Resource
    BizDataService bizDataService;
    @Resource
    BizBaseService bizBaseService;

    @GetMapping("info")
    public IPage<BizData> getInfo(@RequestBody(required = false) BizData bizData, Page<BizData> p){
        SysUserEntity user = SessionSubjectUtils.getUserEntity();
        if (!user.getName().equals("admin")){
            int id = bizBaseService.getIdByName(user.getName());
            BizData bizData1 = new BizData();
            bizData1.setId(id);
            return bizDataService.queryAll(bizData1,p);
        }
        return bizDataService.queryAll(bizData,p);
    }

    @PostMapping("add")
    public int addInfo(@RequestBody BizData bizData){
        return bizDataService.insert(bizData);
    }

//    @DeleteMapping("delete")
//    public int deleteInfo(@RequestBody Map<String,Integer> map){
//        return bizBaseService.deleteInfo(map.get("userId"));
//    }

}
